package edu.liuzihao.listener;

import edu.liuzihao.pojo.ResData;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.annotation.TopicPartition;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Liu
 * @date 2022/12/9 9:22
 **/
@Component
public class SchoolListener {
    public List<String> list = new ArrayList<>();

    @KafkaListener(id = "schoolConsumer", groupId = "niit01", topicPartitions = {
            @TopicPartition(topic = "School", partitions = "0")
    })
    public List<String> res2(List<ConsumerRecord<?, ?>> records) {
        for (ConsumerRecord<?, ?> record : records) {
            list.add((String) record.value());
        }
        System.out.println(list);
        ResData.SchollList = list;
        return list;
    }
}
